//
//  WordMemoryViewController.m
//  Learn
//
//  Created by 迟建国 on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "WordMemoryViewController.h"
#import "WordCardCollectionViewCell.h"
#import "OptionCollectionViewCell.h"

@interface WordMemoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation WordMemoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"开始背单词";
    self.view.backgroundColor = UIColor.whiteColor;
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 44, 44);
    [leftBtn setImage:[UIImage imageNamed:@"icon_home"] forState:UIControlStateNormal];
//    [leftBtn bk_whenTapped:^{
//        
//    }];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn]; 
    [self setUI];
    // Do any additional setup after loading the view.
}

- (void)setUI {
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = rgba(12, 183, 108, 0.1);
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view.mas_top).offset(NavigationBarHeight);
        make.height.offset(28);
    }];
    
    UIImageView *tipImageView = [[UIImageView alloc] init];
    tipImageView.image = [UIImage imageNamed:@"icon_tip"];
    [topView addSubview:tipImageView];
    [tipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView.mas_centerY);
        make.centerX.equalTo(topView.mas_centerX).offset(-70);
        make.width.height.offset(14);
    }];
    
    UILabel *needLearnL = [[UILabel alloc] init];
    needLearnL.text = @"需要学3";
    needLearnL.textColor = rgba(51, 51, 51, 1);
    needLearnL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    [topView addSubview:needLearnL];
    [needLearnL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(topView.mas_centerY);
        make.left.equalTo(tipImageView.mas_right).offset(10);
    }];
    
    UILabel *needReviewL = [[UILabel alloc] init];
    needReviewL.text = @"需复习3";
    needReviewL.textColor = rgba(51, 51, 51, 1);
    needReviewL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    [topView addSubview:needReviewL];
    [needReviewL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(needLearnL.mas_centerY);
        make.left.equalTo(needLearnL.mas_right).offset(32);
    }];
    
    UILabel *contentL = [[UILabel alloc] init];
    contentL.text = @"able adj.能够.....的";
    contentL.textColor = rgba(51, 51, 51, 1);
    contentL.numberOfLines = 0;
    contentL.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [self.view addSubview:contentL];
    [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.top.equalTo(topView.mas_bottom).offset(15);
        make.right.equalTo(self.view.mas_right).offset(-15);

    }];
    
    if (self.type == CardTypeLearn) {
        UILabel *workL = [[UILabel alloc] init];
        workL.text = @"worksss";
        workL.textAlignment = NSTextAlignmentCenter;
        workL.textColor = rgba(51, 51, 51, 1);
        workL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:32];
        [self.view addSubview:workL];
        [workL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(15);
            make.top.equalTo(topView.mas_bottom).offset(195);
            make.right.equalTo(self.view.mas_right).offset(-15);

        }];
        
        UILabel *pinyinL = [[UILabel alloc] init];
        pinyinL.text = @"[a'bAv]";
        pinyinL.textColor = rgba(142, 142, 142, 1);
        pinyinL.textAlignment = NSTextAlignmentCenter;
        pinyinL.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
        [self.view addSubview:pinyinL];
        [pinyinL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(15);
            make.top.equalTo(workL.mas_bottom).offset(10);
            make.right.equalTo(self.view.mas_right).offset(-15);
        }];
    } else {
        UIImageView *readImageView = [[UIImageView alloc] init];
        readImageView.image = [UIImage imageNamed:@"icon_read_46"];
        [self.view addSubview:readImageView];
        [readImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.top.equalTo(topView.mas_bottom).offset(170);
            make.width.height.offset(46);
        }];
    }
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 5; // 水平间距
    layout.minimumLineSpacing = 10; // 垂直间距5或10
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); // 边界间距
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, SCREEN_H - SafeAreaBottomHeight - 225, SCREEN_W, 225) collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.alwaysBounceVertical = YES;
    collectionView.pagingEnabled = NO;
    self.extendedLayoutIncludesOpaqueBars = YES;

    [collectionView registerNib:[UINib nibWithNibName:@"WordCardCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"WordCardCollectionViewCell"];
    [collectionView registerNib:[UINib nibWithNibName:@"OptionCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"OptionCollectionViewCell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//    WordCardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WordCardCollectionViewCell" forIndexPath:indexPath];
//    if (!cell) {
//        cell = [[[NSBundle mainBundle]loadNibNamed:@"WordCardCollectionViewCell" owner:self options:nil] lastObject];
//    }
////    cell.model = self.dataArr[indexPath.row];
//    return cell;
    
    OptionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OptionCollectionViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"OptionCollectionViewCell" owner:self options:nil] lastObject];
    }
    
//    cell.model = self.dataArr[indexPath.row];
    return cell;

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(SCREEN_W - 20, 44);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
